<?php $website_url = Configure::read('Website.url'); ?>
<script type="text/javascript">

    $(document).ready(function(){
        function is_int(input){
            return typeof(input)=='number'&&parseInt(input)==input;
        }
        $('.shippingprice').click(function(){
            $('.shippingprice').removeAttr('id');
            $('label').removeAttr('id');
            $(this).attr('id','selectedprice');
            $(this).parent().attr('id','selectlabel');
        });
        $('.form_btn').click(function(){
            var selected_price = $('#selectedprice').attr('value');
            var subtotal_price =  $('.subtotal b').html();
            subtotal_price =  subtotal_price.replace("$", "");
            var final_total = Number(subtotal_price) + Number(selected_price);
            $('.shippingPrice b').html('$'+selected_price);
            var service_name = $('#selectlabel span').html();
            $('.shipping_servive_name').html(service_name+":");
            $('.item_list_z ul li b.CarttotalPrice').html('$'+final_total);
        });
    });
</script>

<div class="cat_page">
    <div class="cat_page_left">
        <?php //echo $this->element('cat_page_left');?>
    </div>
    <div class="cat_page_right def_div">
        <div class="item_list_show">
            <h2>Shopping Cart</h2>
            <?php
            //pr($current_cart);
            // exit;
            if (isset($current_cart['product_id']) and ($current_cart['product_id'])) {
                ?>
                <div class="def_div f_left">
                    <div class="yourAccMain_L_incv">
                        <!--<div class="yourAccMain_L_in_L">
                          <h2>Enter your destination to get a shipping estimate. </h2>
                        </div>-->
                        <?php //echo $form->create('Product',array('action'=>'','method'=>'post'));  ?>
                        <!--<div class="yourAccMain_L_in_R">
                          <div class="def_div f_left">
                            <div class="acc_form_1">Country :</div>
                            <div class="acc_form_2">
                              <div class="input text required">
                        <?php
                        /* echo $this->Form->input('Shipping.country', 
                          array('type' => 'select','options'=>$countries,
                          'default'=>'US','class'=>'mws-textinput','empty'=>false,'label' =>false)
                          ); */
                        ?>
                              </div>
                            </div>
                          </div>
                          <div class="def_div f_left">
                            <div class="acc_form_1">Region / State :</div>
                            <div class="acc_form_2">
                              <div class="input text required">
                        <?php
                        /* echo $this->Form->input('Shipping.state', 
                          array('type' => 'select','options'=>$states,
                          'default'=>'','class'=>'mws-textinput','empty'=>false,'label' =>false)
                          ); */
                        ?>
                              </div>
                            </div>
                          </div>
                          <div class="def_div f_left">
                            <div class="acc_form_1">Postal Code :</div>
                            <div class="acc_form_2">
                              <div class="input text">
                        <?php
                        echo $this->Form->input('Shipping.Zip', array('type' => 'text', 'required' => true, 'label' => false, 'value' => "", 'class' => 'file1'));
                        ?>
                              </div>
                            </div>
                          </div>
                          <div class="def_div f_left">
                            <div class="acc_form_1">&nbsp;</div>
                            <div class="acc_form_2">
                              <input type="submit" name="" value="Get Quotes" class="add2cart">
                            </div>
                          </div>
                        </div>-->
                        <?php
                        // echo $form->end();
                        ?>
                        <div class="pad_10">&nbsp;</div>
                        <?php
                        if (isset($rate_analysys) and ($rate_analysys)) {
                            ?>
                            <div class="common_border1"></div>
                            <div class="pad_10">&nbsp;</div>
                            <div class="yourAccMain_L_in_L">
                                <h2>Shipping Charges </h2>
                            </div>
                            <div class="yourAccMain_L_in_R">
        <?php
        $Name = array_keys($rate_analysys);

        for ($x = 0; $x < count($Name); $x++) {
            ?>
                                    <h4 ><span class="blue"><?php echo strtoupper($Name[$x]); ?> Shipping Services</span></h4>
                                    <?php
                                    foreach ($rate_analysys['' . $Name[$x] . ''] as $rate) {
                                        ?>
                                        <div class="def_div f_left">
                                            <div class="acc_form_2 f_left">
                                                <label>
                                                    <input class="shippingprice" type="radio" name="data[shipp][rate]"
                                                           value="<?php echo $rate['Rate']; ?>" />
                                                    <span><?php echo $rate['ServiceName']; ?> </span></label>
                                            </div>
                                            <div class="acc_form_1 f_right"><span class="blue">$<?php echo $rate['Rate']; ?></span></div>
                                        </div>
                <?php
            }
        }
        ?>
                                <div class="def_div f_left">
                                    <div class="acc_form_1">&nbsp;</div>
                                    <div class="acc_form_2"><a href="javascript:void(0);" class="form_btn">Add Shipping</a></div>
                                </div>
                            </div>
        <?php
    }
    ?>
                    </div>
                </div>
                <div class="def_div f_left" id="WondereCart">
                    <table width="100%" cellpadding="0" cellspacing="0" class="grid_table_list_2">
                        <tr class="tGb_blk">
                            <th width="20%"><b>Items to buy now </b></th>
                            <th width="1%">&nbsp;</th>
                            <th width="55%">&nbsp;</th>
                            <th width="13%"><b>Price</b></th>
                            <th width="11%"><b>Quantity</b></th>
                        </tr>

                        <!-- This Tr will be repeat-->

    <?php
    $x = 0;
    foreach ($current_cart['product_id'] as $cart) {
        //pr($cart);
        //exit;
        if (($x % 2) == 0) {
            $color = '#fff';
        } else {
            $color = '#efefef';
        }
        ?>
                            <tr bgcolor="<?php echo $color; ?>">
                                <td width="20%" ><?php
                    //echo $html->image('Product/'.$cart['Product']['img'], array('width'=>'133', 'height'=>'100', 'alt'=>$cart['Product']['name']));
                    echo $html->link($html->image('Product/' . $cart['Product']['img'], array('width' => '133', 'height' => '100', 'alt' => $cart['Product']['name'])), array('controller' => 'products', 'action' => 'product', $cart['Product']['slug']), array('escape' => false));
        ?></td>
                                <td width="1%">&nbsp;</td>
                                <td width="55%" ><div class="item_list_z">
                                        <ul>
                                            <li><span class="f_left"><?php echo $html->link($cart['Product']['name'], array('controller' => 'products', 'action' => 'product', $cart['Product']['slug']), array('escape' => false)); ?></span></li>
                                            <li>
                                                <p><a href="javascript:void(0);"> <span class="red"><?php echo $cart['Product']['stock_detail']; ?></span></a></p>
                                            </li>
                                            <li>
                                                <p>Eligible for FREE Super Saver Shipping</p>
                                            </li>
                                            <li>
                                                <p>
                                                    <input type="checkbox" name=""/>
                                                    This will be a gift <a href="#">(Learn more)</a> </p>
                                            </li>
                                            <li>
                                                <p> <?php
                    echo $html->link(
                            "Delete", array('controller' => 'products', 'action' => 'cart', "delete",
                        $cart['Product']['slug']), array('class' => "")
                    );
                    ?>
                                                    |
        <?php
        echo $html->link(
                "Save for Later", array('controller' => 'products', 'action' => 'add_to_wishlist', $cart['Product']['slug']), array('class' => "")
        );
        ?> 
                                                </p>
                                            </li>
                                        </ul>
                                    </div></td>
                                <td width="13%"><div class="item_list_z">
                                        <ul>
                                            <li>
                                                <p><span class="red">$<?php echo $cart['Cart_price']; ?></span></p>
                                                <br />
                                                <p>$<?php echo $cart['product_price']; ?>/Item</p>
                                            </li>
                                            <li>
                                                <p>You Save</p>
                                            </li>
                                            <li>
                                                <p><span class="red"><?php echo __catculate_saving($cart['Product']['msrp'], $cart['product_price']); ?></span></p>
                                            </li>
                                        </ul>
                                    </div></td>
                                <td width="11%"><div class="item_list_z">
                                        <ul>
                                            <li>
                                                <p>
                                                    <input type="text" name="" id="cart<?php echo $cart['id']; ?>" class="price" value="<?php echo $cart['Cart_quantity']; ?>" size="5" />
                                                </p>
                                            </li>
                                            <li>
                                                <p class="cartpriceupdate"> <?php echo $html->link("Update", array('controller' => 'products', 'action' => 'cart', 'add',
                                                $cart['Product']['slug']), array('escape' => false, 'class' => 'cart' . $cart['id'])); ?> 
                                                  <!--<a href="javascript:void(0);" class="cart<?php //echo $cart['id'];  ?>">Update</a>--> 
                                                </p>
                                            </li>
                                        </ul>
                                    </div></td>
                            </tr>
                            <tr >
                                <td width="100%" colspan="5"><div class="common_border"></div></td>
                            </tr>
        <?php
        $x++;
    }
    ?>
                        <!-- This Tr will be repeat-->

                        <tr >
                            <td width="20%">&nbsp;</td>
                            <td width="1%">&nbsp;</td>
                            <td width="55%">&nbsp;</td>
                            <td width="13%"><div class="item_list_z">
                                    <ul>
                                        <li>
                                            <p><b>Subtotal :</b></p>
                                        </li>
                                        <li>
                                            <p><b class="shipping_servive_name"></b></p>
                                        </li>
                                    </ul>
                                </div></td>
                            <td width="11%"><div class="item_list_z">
                                    <ul>
                                        <li>
                                            <p><span class="red subtotal"><b>$<?php echo $current_cart['total_price']; ?></b></span></p>
                                        </li>
                                        <li>
                                            <p><span class="red shippingPrice"><b></b></span></p>
                                        </li>
                                    </ul>
                                </div></td>
                        </tr>
                        <tr style="background:#357AAB;">
                            <td width="20%">&nbsp;</td>
                            <td width="1%">&nbsp;</td>
                            <td width="55%">&nbsp;</td>
                            <td width="13%" ><div class="item_list_z f_right" style="font-size:17px; color:#fff; text-align:left;">
                                    <ul>
                                        <li> <b>Grand Total :</b> </li>
                                    </ul>
                                </div></td>
                            <td width="11%" ><div class="item_list_z" style="font-size:17px; color:#fff; text-align:left;" >
                                    <ul>
                                        <li><b class="CarttotalPrice">$<?php echo $current_cart['total_price']; ?></b> </li>
                                    </ul>
                                </div></td>
                        </tr>
                        <tr>
                            <td width="100%" colspan="5"><div class="common_border"></div></td>
                        </tr>
                        <tr>
                            <td width="20%">&nbsp;</td>
                            <td width="1%">&nbsp;</td>
                            <td width="55%">&nbsp;</td>
                            <td width="13%">&nbsp;</td>
                            <td width="11%"><?php echo $html->link('Checkout', array('controller' => 'products', 'action' => 'checkout'), array('class' => 'next_link f_left')); ?></td>
                        </tr>
                        <tr>
                            <td width="20%">&nbsp;</td>
                            <td width="1%">&nbsp;</td>
                            <td width="55%">&nbsp;</td>
                            <td width="24%" colspan="2"><?php echo $html->link('Continues Shopping', array('controller' => 'products', 'action' => 'index'), array('class' => 'org_link f_right')); ?></td>
                        </tr>
                    </table>
                </div>
    <?php
} else {
    echo "Sorry You have Empty Cart.";
}
?>
            <div class="def_div f_left"> </div>
        </div>
    </div>
</div>
